package Service.Impl;

import Bean.User;
import Dao.Impl.UserDaoImpl;
import Dao.UserDao;
import Service.MemberService;
import Utils.MysqlTool;

public class MemberServiceImpl implements MemberService {
    public static void main(String[] args) {
        String username = "peng123";
        String password = "qwe123";
        MemberServiceImpl memberService = new MemberServiceImpl();
        memberService.LoginUser(username,password);
    }
    private UserDaoImpl userDao= new UserDaoImpl();
    public boolean registerUser(User user) {
        int i = userDao.saveUser(user);
        if (i == -1)
        {
            return false;
        }
        return true;
    }

    @Override
    public boolean isExistsUsername(String username) {
        User user = userDao.getUser(username);
        if (user == null){
            return false;
        }
        return true;
    }

    @Override
    public boolean LoginUser(String username, String password) {
        User user = userDao.getUser(username);
        if (user == null){
            return false;
        }
        String md5passWord = userDao.getMD5passWord(password);

        if (!user.getPassWord().equals(md5passWord)){
            return false;
        }
        return true;
    }

    @Override
    public User getUser(String username) {
        return userDao.getUser(username);
    }
}
